package CaseDemo;

import java.util.ArrayList;
import java.util.Random;

public class groupLeader {
	private String name;
	private double money;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getMoney() {
		return money;
	}
	public void setMoney(double money) {
		this.money = money;
	}
	
	groupLeader(String name, double money) {
		this.name = name;
		this.money = money;
	}
	
	public void show(){
		System.out.println("�ҵ����Ϊ:"+money);
	}
	
	public ArrayList<Double> send(double totalSend, int count){
		//������
		double leftMoney = this.getMoney();
		if(totalSend>leftMoney){
			System.out.println("����");
			return null;
		}
		this.setMoney(money-totalSend);
		
		//�����
		ArrayList<Double> redList = new ArrayList<>();
		int restCount = count;
		Random r = new Random();
		for(int i=0; i<count-1; i++){
			double rangeMax = totalSend/restCount * 2;
			//ÿһ�ݵ������Χ,��Сֵ1,���ֵΪ��ǰʣ��ƽ������2��
			
			double single = Math.floor((1+(r.nextDouble()*rangeMax))*100)/100;
			redList.add(single);
			totalSend -= single;
			restCount--;
		}
		totalSend = Math.round(totalSend * 100.0) / 100.0;
        redList.add(totalSend);
		
		return redList;
	}
	
	public void receive(ArrayList<Double> redList){
		Random r = new Random();
		int index = r.nextInt(redList.size());
		double temp = redList.remove(index);
		this.setMoney(temp+this.getMoney());
		System.out.println(this.name+"����"+temp+"Ԫ");
		
	}
	
	

}
